function [dd interpoluton_cons acc] = SFO_Correction(dd, start,Mini_probe...
    ,interpoluton_cons_last,iteration,update_num,acc,pkt)


persistent index_last;
persistent temp;


lut = [-1*(update_num*(1148/100000)),...
        1*(update_num*(1148/100000))];


Rx_Work = dd(start:start+31*4+1);
Actual_Rx1 = interp1(1:length(Rx_Work),Rx_Work,(1+lut(1)):length(Rx_Work));
Actual_Rx2 = interp1(1:length(Rx_Work),Rx_Work,(1+lut(2)):length(Rx_Work));

Actual_Rx =  [Actual_Rx1(2:end-1);...
    Actual_Rx2(2:end)];


x=zeros(1,2);


for range =1:2
    x(range) = abs(sum(conj(Mini_probe).*Actual_Rx(range,:)));
end

[maimum index] = max(x);


if acc < 0.1
    acc = 0.1;
end
if iteration == 1
    temp = [];
end

temp = [temp lut(index)*acc];
temp1 = mean(temp);
interpoluton_cons = interpoluton_cons_last + temp1;
% to show variables below
z = interpoluton_cons ;
y = index;


Rx_edited = dd(start+31*4:start+(31+256)*4*update_num+31*4+1);
Rx_edited = interp1(1:length(Rx_edited),Rx_edited,...
    2+interpoluton_cons_last:1+temp1/1148:length(Rx_edited));



if abs(interpoluton_cons) < (update_num*(1/1000))
    interpoluton_cons = 0;
end


if interpoluton_cons < 0
    dd(start+1+31*4:start+(31+256)*4*update_num+31*4) =  Rx_edited(1:end-1);
elseif interpoluton_cons == 0
    return;
else
    dd(start+1+31*4:start+(31+256)*4*update_num+31*4) =  Rx_edited(1:end);
end


if pkt == 1
if index == index_last
    acc = acc + 0.09;
else
    acc = acc - 0.09;
end
else
if index == index_last
    acc = 1;
else
    acc = 1;
end
end

index_last = index;

end